<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/publicPage.jsp" %>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>编辑手机用户</title>
    <%@ include file="/publicLink.jsp" %>
    <%@ include file="/publicjQueryJS.jsp" %>
    <%@ include file="/publicValidation.jsp" %>
    <%@ include file="/publicFormJS.jsp" %>

    <script type="text/javascript">
        var dialog = frameElement.dialog;
        $(function () {
            $.metadata.setType("attr", "validate");
            var v = $("form").validate({
                rules: {
                    name: {
                        remote: "/rest/message/phoneUserNameOnly?phoneNum=" + $("#phoneNum").val()
                    }
                },
                messages: {
                    name: {
                        remote: $.format("数据已经存在，请重新填写")
                    }
                },
                //调试状态，不会提交数据的
                debug: true,
                //字段不为空的验证样式


                errorPlacement: function (lable, element) {
                    if (element.hasClass("l-textarea")) {
                        element.addClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field")) {
                        element.parent().addClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                    $(element).attr("title", lable.html()).ligerTip();
                },


                success: function (lable) {
                    var element = $("#" + lable.attr("for"));
                    if (element.hasClass("l-textarea")) {
                        element.removeClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field")) {
                        element.parent().removeClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                },

                //添加
                submitHandler: function () {


                    var type = $("#type").val();
                    $("form .l-text,.l-textarea").ligerHideTip();
                    if (type == "add") {
                        $.ajax({
                            type: "POST",
                            url: '/rest/message/phoneUserAdd',
                            data: $('#formPhoneUser').serialize(),
                            async: false,
                            success: function (data) {
                                window.parent.okdialog();
                                window.parent.loadData();
                                window.parent.closeDialog();
                            },
                            error: function (request) {
                                $.ligerDialog.success('操作失败!', function () {
                                    window.parent.loadData();
                                    window.parent.closeDialog();
                                });
                            }
                        });
                    }


                    //如果是type是修改
                    if (type == "update") {
                        $.ajax({
                            type: "POST",
                            url: '/rest/message/phoneUserUpload',
                            data: $('#formPhoneUser').serialize(),
                            async: false,
                            success: function (data) {
                                window.parent.okdialog();
                                window.parent.loadData();
                                window.parent.closeDialog();
                            },
                            error: function (request) {
                                $.ligerDialog.success('操作失败!', function () {
                                    window.parent.loadData();
                                    window.parent.closeDialog();
                                });
                            }
                        });
                    }
                }
            });

            $("formPhoneUser").ligerForm();
            $(".l-button-test").click(function ()
            {
                //关闭填出框
                // window.parent.closeDialog();
                dialog.close();
            });
        });
        $(function(){
            //调整宽度
            $(".tcmPrintingPlant").ligerComboBox({
                width: 400
            });
        });


    </script>
</head>
<body style="padding:10px">
<form name="formPhoneUser" method="post" action="" id="formPhoneUser">
    <table cellpadding="0" cellspacing="0" class="l-table-edit" align=center valign=middle>
        <tr>
            <td align="left">
                <input id="type" value="${type}" type="hidden">
                <input id="id" name="id" value="${phoneUser.id}" type="hidden">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">用户名:</td>
            <td align="left" class="l-table-edit-td">
                <input class="puserName" name="puserName" type="text" id="puserName" ltype="text"
                       value="${phoneUser.puserName}" validate="{required:true,minlength:1,maxlength:100}"/>
            </td>
            <td align="left"></td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">用户号码:</td>
            <td align="left" class="l-table-edit-td">
                <input class="phoneNum" name="phoneNum" type="text" id="phoneNum" ltype="text"
                       value="${phoneUser.phoneNum}"/>
            </td>
            <td align="left"></td>
        </tr>
    </table>
    <br/>
    <input type="submit" name="提交" value="提交" id="" class="l-button l-button-submit"/>
    <input type="button" name="关闭" value="关闭" class="l-button l-button-test"/>
</form>
</body>
</html>
